$(function(){
	e();
});

function e(){
	$(".form-btn2").on("click",function(){

		// window.location.href = "register_sus.html";
	});
}
function le_error_message(le_position,message){
    if($("div").hasClass("le-error-message")){
        $(le_position).text(message).fadeIn();
        $(le_position).delay(2000).fadeOut();
    }
}

$(".le-register-addinfo-form .register_submit").on("click",function(){
    var name = $("input[name='name']").val(),
        code = $("input[name='code']").val(),
        mobile = $("input[name='mobile']").val(),
        grade = $("select[name='grade']").val(),
        subject = $("select[name='subject']").val();

    if(!mobile){
        //le_error_message("'.le_mobile>.le-error-message","手机号码不能为空");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(mobile))){
        //le_error_message("'.le_mobile>.le-error-message","手机号码有误");
        return false;
    }

    if(!name){
        //le_error_message("'.le_name>.le-error-message","姓名不能为空");
        return false;
    }
    if(!grade){
        //le_error_message(".le_grade>.le-error-message","年级不能为空");
        return false;
    }
    if(!subject){
        //le_error_message("'.le_subject>.le-error-message","课程不能为空");
        return false;
    }

    var post = {'name':name,'code':code,"mobile":mobile,"grade":grade,"subject":subject};
    $.ajax({
        type: "POST",dataType:"json", url: "", data: post,
        success: function(data) {console.log(data);
            if (data.code) {
                //dr_tips('注册成功，即将为您跳转....', 3, 1);
                $(".register_submit").text("注册成功，即将为您跳转....").css("background","rgb(189, 189, 189)").css("font-size","16px");
                setTimeout('window.location.href="'+'index.php?s=user&c=login&m=index'+'"', 2000);
            } else {
                $('#dr_code_img').click();
                le_error_message("'.le-error-message",data.msg);
                //dr_tips(data.msg,3,1);
            }
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            alert(HttpRequest.responseText);
        }
    });

    // window.location.href = "register_sus.html";
});

$(".poup_register_info .register_submit").on("click",function(){
    var name = $("input[name='name']").val(),
        code = $("input[name='code']").val(),
        mobile = $("input[name='mobile']").val(),
        grade = $("select[name='grade']").val(),
        subject = $("select[name='subject']").val();

    if(!mobile){
        //le_error_message("'.le_mobile>.le-error-message","手机号码不能为空");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(mobile))){
        //le_error_message("'.le_mobile>.le-error-message","手机号码有误");
        return false;
    }

    if(!name){
        //le_error_message("'.le_name>.le-error-message","姓名不能为空");
        return false;
    }
    if(!grade){
        //le_error_message(".le_grade>.le-error-message","年级不能为空");
        return false;
    }
    if(!subject){
        //le_error_message("'.le_subject>.le-error-message","课程不能为空");
        return false;
    }

    var post = {'name':name,'code':code,"mobile":mobile,"grade":grade,"subject":subject};
    $.ajax({
        type: "POST",dataType:"json", url: "", data: post,
        success: function(data) {console.log(data);
            if (data.code) {
                //dr_tips('注册成功，即将为您跳转....', 3, 1);
                $(".register_submit").text("注册成功，即将为您跳转....").css("background","rgb(189, 189, 189)").css("font-size","16px");
                setTimeout(function () {
                    window.location.href='./index.php?s=user&c=login&m=poup_login';
                }, 2000);
                $(window.parent.document).find("#login-title").addClass("active");
                $(window.parent.document).find("#registor-title").removeClass("active");
            } else {
                $('#dr_code_img').click();
                le_error_message("'.le-error-message",data.msg);
                //dr_tips(data.msg,3,1);
            }
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            alert(HttpRequest.responseText);
        }
    });

    // window.location.href = "register_sus.html";
});


$('[name~=grade]').css('color','#9e9e9e');
$('[name~=grade]').change(function() {
    var current = $('[name~=grade]').val();
    if (current != '') {
        $('[name~=grade]').css('color','#333333');
    } else {
        $('[name~=grade]').css('color','#9e9e9e');
    }
});
$('[name~=subject]').css('color','#9e9e9e');
$('[name~=subject]').change(function() {
    var current = $('[name~=subject]').val();
    if (current != '') {
        $('[name~=subject]').css('color','#333333');
    } else {
        $('[name~=subject]').css('color','#9e9e9e');
    }
});
$( ".input-name" ).focusout(function(){
    var name = $(".input-name").val();
    if(!name){
        le_error_message(".le_name>.le-error-message","姓名不能为空");
        return false;
    }
});
$('[name~=grade]' ).focusout(function(){
    var name = $(".le-register-addinfo-form .le_grade select").val();
    if(!name){
        le_error_message(".le_grade>.le-error-message","年级不能为空");
        return false;
    }
});
$( "[name~=subject]" ).focusout(function(){
    var name = $(".le-register-addinfo-form .le_subject select").val();
    if(!name){
        le_error_message(".le_subject>.le-error-message","课程不能为空");
        return false;
    }
});